package com.gton.person.commons.hander;

import com.gton.person.service.RoleService;
import com.gton.person.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @program: PersonalDesign
 * @description: 项目一启动就执行redis缓存
 * @author: GuoTong
 * @create: 2020-12-28 10:26
 **/
@Slf4j
@Component
@Order(value = 1)
public class MyApplicationRunner implements ApplicationRunner {

    /**
     * 权限处理业务逻辑service
     */
    @Autowired
    private RoleService roleService;

    /**
     * setUserIdAndUserNameAndLoginIdInRedis
     * @param args
     * @throws Exception
     */
    @Autowired
    private StudentService studentService;


    @Override
    public void run(ApplicationArguments args) throws Exception {
        //项目初始化就执行吧用户表的名字和权限加载到redis
        roleService.loadingNameAndRolesInredis();
        //把用户ID和用户名，活用登录ID存入Redis，常用的不要频繁的访问数据MYSQL数据库
        studentService.setUserIdAndUserNameAndLoginIdInRedis();
    }
}
